package com.ramos.kuaixiao.utils;

import android.util.Log;

import com.ramos.kuaixiao.db.ProductTypeDB;
import com.ramos.kuaixiao.db.ShopsDB;
import com.ramos.kuaixiao.entity.ProductType;
import com.ramos.kuaixiao.entity.ShopTypeBean;
import com.ramos.kuaixiao.entity.ShopTypeBean.ShopType.ProductInfo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class Test {
    private static String TAG = "Test";

    public ShopTypeBean getProductByBrand() throws Exception {
        ProductInfo info = new ProductInfo();
        //info.setDealerId(dealerId);
        //info.setBrandId(brandId);
        ShopTypeBean res = new ShopTypeBean();
        if (info.getStatus() == null || info.getStatus().equals("")) {
            info.setStatus("审核");
        }
        List<ShopTypeBean.ShopType.ProductInfo> infoList = new ShopsDB().findAllUseShops();//本地获取所有的符合条件的商品this.productInfoMapper.getProductInfoByCondition2(info);
        Log.d(TAG, "infoList:" + infoList.size());
        List<ProductType> typeList = new ProductTypeDB().findAllProductType();//本地获取所有的keywords；typeMapper.getAllKeywords(dealerId);
        Log.d(TAG, "typeList:" + typeList.size());
        HashMap<String, ArrayList<String>> typeMap = new HashMap<>();
        if (typeList != null && typeList.size() > 0) {
            for (ProductType type : typeList) {
                type.recoverTypeId();
                ArrayList<String> keyset = new ArrayList<>();
                String[] keywords = type.getComment().split("_");
                for (String key : keywords) {
                    keyset.add(key);
                }
                typeMap.put(type.getTypeId(), keyset);
            }
        }
        for (String key : typeMap.keySet()) {
            Log.d(TAG, "typeMap:key= " + key + " and value= " + typeMap.get(key));
        }
        Log.d(TAG, "typeMap:" + typeMap.size());
        if (infoList != null && infoList.size() > 0) {
            for (ShopTypeBean.ShopType.ProductInfo ii : infoList) {
                ii.recoverproductInfoId();
                if (!ii.getStatus().equals("暂停销售")) {
                    res.addProductInfo(ii, typeMap);
                }
            }
        }
        Log.d(TAG, "res:" + res.getBrandList().size());
        for(ShopTypeBean.ShopType shopType :  res.getBrandList()){
            Log.d(TAG, "resshopType:" + shopType.getBrandId() + " " + shopType.getBrandName() + " " + shopType.getTypeGroupList().size());
            if(shopType.getTypeGroupList().size() > 0 ){
                for(ShopTypeBean.ShopType.Type  type : shopType.getTypeGroupList()){
                    Log.d(TAG, "restype:" + type.getTypeId() + " " + type.getTypeName() + " " + type.getTypeGroupList().size());
                    if(type.getTypeGroupList().size() > 0){
                        for(ShopTypeBean.ShopType.Product productInfo : type.getTypeGroupList()){
                            Log.d(TAG, "resproductInfo:" + productInfo.getTypeId() + " " + productInfo.getTypeName() + " " + productInfo.getProductInfoNameList().size());
                        }
                    }
                }
            }
        }
        return res;
    }
}
